
/*************************************************************************
* Copyright (c) 2008, ShenZhen Coship Electronic Ltd Co.
* All rights reserved.
* 
* File Name:		CDJpeg.cpp
* Summary:			implementation of the CCDJpeg class.
* 
* Current Version:	1.0
* Author(s):
/------------------------------------------------------------------------/
revision			author				reason					date
1.0					Ding Ning			Initialize Version		2008-6-18
/------------------------------------------------------------------------/
*************************************************************************/

#pragma once

#include "SyncObj.h"
#include "IMMP4.h"

class CircleBuf
{
public:
	CircleBuf();
	~CircleBuf();

	bool Create(int size);
	void Release();
	int Read(void* buf, int size);
	int Write(void* buf, int size);
	int GetStock();
	void Reset();

protected:
	char* m_pBuf;
	int m_nSize;
	int m_nStock;
	int m_nReadPos;
	int m_nWritePos;
	MyEvent m_evtNoEmpty;
	MyEvent m_evtNoFull;
	DWORD m_nTimeout;
	CritSect m_csAccess;
};

class DecBuf : public CIBuffer
{
public:
	DecBuf(CircleBuf* buf);
	~DecBuf();

	virtual HRESULT CreateObj(); 
	virtual HRESULT Read(void* buf, size_t bufsize, size_t* readed); 
	virtual HRESULT Rewind();
	virtual HRESULT	Release();

	void Stop();
	CircleBuf* GetCir(){return m_pCirBuf;};

protected:
	CircleBuf* m_pCirBuf;
	bool m_bStop;
};
